<template>
  <div>
    <!-- :params="fetchParams" -->
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="list"
      :height="400"
      :isColumnFilter="false"
      :isToperInfo="false"
      :isSelectColumn="false"
      :onSyncTableData="syncTableFun"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <!-- <template slot="controls" slot-scope="props">
           <el-button
             size="small"
             type="primary"
             icon="el-icon-plus"
             @click="addWxxmHandle()"
           >新增</el-button>
         </template> -->
    </FilterTable>
    <!-- <BaseDialog
      :visible.sync="visibleWxxm"
      title="维修项目选择"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
      destroyOnClose>
      <AddWxxm  ref="addWxxm"  @closeWx="closeAddwxxm" />
    </BaseDialog> -->
  </div>
</template>
<script>
// import AddWxxm from '../addXM/addwxxm';
import { dictionary } from '@/utils/dictMixin';
import { detailsWxxm, getPartitionList, timeonce, getLAbourCode,getModelLabourCode } from '@/api/repair/repair/activitesManage';
// import { getFwhdWxxmList , getFwhdSfList ,getFwhdWxlxList ,getFwhdGsdjList} from '@/api/repair/repairReception/customer/activity.js';
let _this;
export default {
  name: 'Wxxm',
  components: {
    // AddWxxm
  },
  mixins: [dictionary],
  props: ['detaildata'],
  data() {
    return {
      visibleWxxm: false,
      columns: this.createTable(),
      // fetchParams: { xhrAbort: false},
      list: [],
      tableData: []
    };
  },
  created() {
    _this = this;
    _this.timeonce();
    this.getLAbourCode();
    _this.getPartitionList();
    _this.detailsWxxm();
  },
  mounted() {},
  methods: {
    // 获取工时单价下拉框
    async timeonce() {
      const res = await timeonce();
      this.columns[8].editItems = res.data.map(x => ({ value: x.LABOUR_PRICE, text: x.LABOUR_PRICE }));
    },
    // 获取收费区分下拉框
    async getPartitionList() {
      const res = await getPartitionList();
      this.columns[5].editItems = res.data.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    // 获取维修项目方法
    async detailsWxxm() {
      let res = await detailsWxxm(this.detaildata);
      res.data.rows.forEach(x => {
        if (x.REPAIR_TYPE_CODE != null) {
          x.LABOUR_PRICE = Number(x.LABOUR_PRICE);
        } else {
          x.LABOUR_PRICE = null;
        }
        // STD_LABOUR_HOUR收费工时
        // ASSIGN_LABOUR_HOUR派工工时
        // LABOUR_PRICE工时单价
        // LABOUR_AMOUNT工时费
        // DISCOUNT折扣率
        // LABOUR_AMOUNT_DISCOUNT折扣后工时费
        if (x.LABOUR_PRICE != '' && x.LABOUR_PRICE != null && x.LABOUR_PRICE != undefined) {
          x.LABOUR_AMOUNT = Number(x.STD_LABOUR_HOUR) * Number(x.LABOUR_PRICE);
        }
        if (isNaN(Number(x.DISCOUNT))) {
          x.LABOUR_AMOUNT_DISCOUNT = 0;
        } else {
          x.LABOUR_AMOUNT_DISCOUNT = Number(x.LABOUR_AMOUNT) * Number(x.DISCOUNT);
        }
        if (x.LABOUR_PRICE === 0) {
          x.LABOUR_PRICE = '';
        }
        if(x.CHARGE_PARTITION_CODE == 'S'||x.CHARGE_PARTITION_CODE == 'N'){
          x.LABOUR_AMOUNT_DISCOUNT = 0;
        }
      });
      _this.$refs.table.$refs.pageTable.EXECUTE_INSERT(res.data.rows);
    },
    // closeAddwxxm (val) {
    //    this.visibleWxxm = false
    //     if (val != false){
    //       this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val)
    //     }
    // },
    ceshi(val) {
      _this.$emit('changeone', _this.list);
    },
    // 传给父组件的数据
    syncTableFun(val) {
      this.tableData = val;
    },
    // addWxxmHandle() {
    //   this.visibleWxxm=true
    // },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //     title: '操作',
        //     dataIndex: 'column-action',
        // },
        {
          title: '项目车系',
          dataIndex: 'MODEL_LABOUR_NAME',
          sorter: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '维修项目代码',
          dataIndex: 'LABOUR_CODEF',
          sorter: true
        },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_NAME',
          sorter: true
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filterItems: [],
          editable: true,
          editType: 'select',
          disabled: true,
          editItems: []
          // render: props => {
          //   return <span>{this.func(props.row.REPAIR_TYPE_CODE,5)}</span>;
          //   }
        },

        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filterItems: [],
          editable: true,
          editType: 'select',
          editItems: [],
          disabled: true
          // render: props => {
          //   return <span>{this.func(props.row.CHARGE_PARTITION_CODE,6)}</span>;
          //   }
        },
        {
          title: '收费工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          summation: true
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          summation: true,
          editable: true,
          editType: 'select',
          precision: 2,
          disabled: true,
          editItems: []
          //  render: props => {
          //   return <span>{}</span>;
          //   }
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true
        },
        {
          title: '折扣后工时费',
          dataIndex: 'LABOUR_AMOUNT_DISCOUNT',
          sorter: true,
          precision: 2,
          summation: true
        }
      ];
    },
    // 维修项目表单数据删除
    delete(val) {
      let a = [];
      a.push(val);
      this.$refs.table.$refs.pageTable.EXECUTE_DELETE(a);
    },
    async getFwhdWxxmList(row) {
      const res = await getFwhdWxxmList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list = res.rows;
    },
    async getFwhdSfList() {
      const res = await getFwhdSfList();
      this.columns[6].filterItems = res.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    async getFwhdWxlxList() {
      const res = await getFwhdWxlxList();
      this.columns[5].filterItems = res.map(x => ({ value: x.REPAIR_TYPE_CODE, text: x.REPAIR_TYPE_NAME }));
    },
    // 项目维修代码下拉框获取方法
    async getLAbourCode() {
      const res = await getLAbourCode();
      if (res.resultCode == 200) {
        this.columns.find(x => x.dataIndex === 'REPAIR_TYPE_CODE').editItems = res.data.map(x => ({ value: x.REPAIR_TYPE_CODE, text: x.REPAIR_TYPE_NAME }));
      }
      const res1 = await getModelLabourCode();
      if (res.resultCode == 200) {
        this.columns.find(x => x.dataIndex === 'MODEL_LABOUR_NAME').editItems = res1.data.map(x => ({ value: x.SERIES_ID, text: x.MODEL_LABOUR_NAME }));
      }
    },
    func(val, num) {
      if (val) {
        const res = this.columns[num].filterItems.find(x => x.value == val);
        return res.text;
      }
    }
  }
};
</script>
